package org.jypj.dev.controller;

import org.jypj.dev.dao.IMacDao;
import org.jypj.dev.model.Mac;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ChenYu on 2017-05-31.
 */
@Controller
public class MacController {

    @Resource
    private IMacDao macDao;

    /**
     * 保存
     *
     * @return
     */
    @RequestMapping(value = "mac/save")
    public String toSaveMac(HttpServletRequest request) {
        List<Mac> macs = macDao.selectAll();
        request.setAttribute("macs", macs);
        return "back/sys/mac_save";
    }

    /**
     * 保存
     * @param mac
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "saveMac")
    public Map<String, Object> saveMac(Mac mac) {
        Map<String, Object> dataMap = new HashMap<>();
        int code = 0;
        try {
            macDao.saveMac(mac);
        } catch (Exception e) {
            e.printStackTrace();
            code = -1;
        }
        dataMap.put("code", code);
        return dataMap;
    }
}
